<!DOCTYPE html>
<html>
<head>
	<include file="Public:common-css" />
	<link type="text/css" rel="stylesheet" href="__ICSS__/member.css" />
	<link rel="stylesheet" type="text/css" href="__ICSS__/pikaday.css"/>
</head>
<body>
<div class="container">
<!-------------------------header--------------------------------->
<include file="Public:header" />
<!--------------------------content------------------------------->
	<div class="clr"></div>
    <div class="content">
    	<include file="Public:member-left" />
        <div class="member-right">
        	<div class="member-breadcrumbs">
            	<a href="__ROOT__">首页</a>
                &gt;
                <span>个人中心</span>
                &gt;
                <span>订单列表</span>
            </div>
            <div class="m-title">
                <form action="__ROOT__/Order<notempty name='param.status'>?status=<{$param.status}></notempty>" method="post" class="detailForm">
                	<font>订单时间：</font>
                   	<span class="search-box"><input type="text" class="search-input" readonly id="datepicker" name="create_time_begin" value="<{$param.create_time_begin}>"/><i></i></span>
                   	<font>至</font>
                   	<span class="search-box"><input type="text" class="search-input" readonly id="datepicker2" name="create_time_end" value="<{$param.create_time_end}>"/><i></i></span>
                  	<font class="m-l5">订单编号：</font>
                    <input type="text" class="search-input search-input-l" name="code" value="<{$param.code}>"/>
                  	<input type="submit" class="member-search-btn" value="搜寻"/>
                </form>
            </div>
            <!-- 订单列表开始 -->
            <div class="clr"></div>
          	<table width="980" border="0" class="order-t-table msyh">
              	<tr>
           	      <td width="44%" height="40" align="center" valign="middle">商品信息</td>
                  <td width="10%" height="40" align="center" valign="middle">数量</td>
           	      <td width="14%" height="40" align="center" valign="middle">单价</td>
                  <td width="12%" height="40" align="center" valign="middle">总价</td>
           	      <td width="10%" height="40" align="center" valign="middle">交易状态</td>
                  <td width="10%" height="40" align="center" valign="middle">交易操作</td>
       	    	</tr>
          	</table>
          	<foreach item="list" name="list">
            <div class="o-table msyh">
           	  <table width="978" border="0">
            	  <tr>
            	    <th height="32" colspan="7" align="left" valign="middle" style="text-align:left;"><span><{$list.create_time|date="Y-m-d H:i:s",###}></span><span>订单编号：<{$list.code}></span></th>
           	    </tr>
                <!--有记录的状态-->
                <foreach item="pro" name="list.productList">
            	 <tr>
            	    <td width="9%" height="40" align="center"><a href="__ROOT__/Product/details?productId=<{$pro.product_id}>" class="order-photo"><img src="__IMGROOT__<{$pro.photo}>" width="80" height="80"/></a></td>
            	    <td width="35%" height="40" align="left" valign="top">
                    	<div class="order-info">
                            <strong><{$pro.name}></strong>
                        </div>
                    </td>
                    <td width="10%" height="40" align="center" valign="middle"><{$pro.num}></td>
            	    <td width="14%" height="40" align="center" valign="middle">
           	    	  <p class="o-price">￥<{$pro.price}></p>
                    </td>
                    <if condition="$key eq 0">
                    <td width="12%" rowspan="<{:count($list)}>" class="l-b-table" align="center" valign="top">
                    	<font class="order-price">￥<{:formatPrice($list['real_price'] + $list['mail_fee'])}></font>
                    	<p>含运费:￥<{$list.mail_fee}></p>
                    </td>
            	    <td width="10%" rowspan="<{:count($list)}>" class="l-b-table" align="center" valign="top">
            	    	<switch name="list.status">
            	    		<case value="1">等待付款</case>
            	    		<case value="2">已付款</case>
            	    		<case value="3">配送中</case>
            	    		<case value="4">完成</case>
            	    		<case value="0">退款处理中</case>
            	    		<case value="-1">失效</case>
            	    		<case value="-2">退款完成</case>
            	    		<case value="-3">拒绝退款</case>
            	    	</switch>
            	    	<br/>
            	    	<a href="__ROOT__/Order/details?code=<{$list.code}>">订单详情</a>
            	    </td>
                    <td width="10%" rowspan="<{:count($list)}>" class="l-b-table" align="center" valign="top">
                    	<switch name="list.status">
            	    		<case value="1">
            	    			<a class="order-config-btn" href="__ROOT__/Order/payment?orderCode=<{$list.code}>">去付款</a>
            	    			<a class="" href="javascript:void(0)" ref="<{$list.code}>" onclick="cancelOrder(this)">取消订单</a>
            	    		</case>
            	    		<case value="2">
            	    			<a class="" href="javascript:void(0)" ref="<{$list.code}>" onclick="applyReturnOrder(this)">申请退款</a>
            	    		</case>
            	    		<case value="3">
            	    			<a class="order-config-btn" href="javascript:void(0)" ref="<{$list.code}>" onclick="doneOrder(this)">确定收货</a>
            	    			<a class="" href="javascript:void(0)" ref="<{$list.code}>" onclick="applyReturnOrder(this)">申请退款</a>
            	    		</case>
            	    		<case value="4">完成</case>
            	    		<case value="0">退款处理中</case>
            	    		<case value="-1">失效</case>
            	    		<case value="-2">退款完成</case>
            	    		<case value="-3">
            	    			<a class="order-config-btn" href="javascript:void(0)" ref="<{$list.code}>" onclick="doneOrder(this)">确定收货</a>
            	    		</case>
            	    	</switch>
                    </td>
                    </if>
          	    </tr>
                </foreach>
          	  </table>
            </div>
            </foreach>
            <empty name="list"><p class="no-more-box"><img src="__IIMG__/no-order.png" width="80"/><span>没有订单记录</span></p></empty>
            <div class="clr"></div>
            <!-- 订单列表结束 -->
            <div class="page">
            	<ul>
            		<{$page}>
                </ul>
            </div>
        </div>
    </div>
    <div class="clr"></div>
<!--------------------------content-end--------------------------->
    <include file="Public:footer" />
</div>

</body>
<include file="Public:common-js" />
<script type="text/javascript" src="__IJS__/pikaday.min.js"></script>
<script type="text/javascript">
$(function(){
	//获得input
	var $nDate = $("#datepicker");
	var $pDate = $("#datepicker2");
	//获得当前时间和清空input值
	var nowDate = new Date();

    var picker = new Pikaday(
    {
        field: document.getElementById('datepicker'),
        firstDay: 1,
        minDate: new Date('2010-01-01'),
        maxDate: new Date(nowDate),
        yearRange: [2000,2020]
    });
    var picker2 = new Pikaday({
		field: document.getElementById('datepicker2'),
        firstDay: 1,
        minDate: new Date($nDate.val()),
        maxDate: new Date(nowDate),
        yearRange: [2000,2020]
    });

    //动态改变时间值
    $nDate.change(function(){
    	var sdate = new Date($nDate.val());
    	sdate.setDate(sdate.getDate()-1);
    	picker2._o.minDate = sdate;
        picker2.render()
    })
    $pDate.change(function() {
		picker._o.maxDate = new Date($pDate.val());
		picker.render();
    })
    //比对时间
    function compare(a, b) {
	    var arr = a.split("-");
	    var starttime = new Date(arr[0], arr[1], arr[2]);
	    var starttimes = starttime.getTime();
	
	    var arrs = b.split("-");
	    var lktime = new Date(arrs[0], arrs[1], arrs[2]);
	    var lktimes = lktime.getTime();
	
	    if (starttimes > lktimes) {
	        return false;
	    }
	    else
	        return true;
	}
	//表单验证
   $(".detailForm").submit(function() {
		if($nDate.val() == "" || $pDate.val() == ""){
			alert("请选择订单起止时间");
			return false;
		}
		if(compare($nDate.val(),$pDate.val()) == false){
			alert("开始时间不能大于结束时间");
			return false;
		}
	})
	//设置默认时间
	var vYear = nowDate.getFullYear();
	var vMon = nowDate.getMonth() + 1;
	var vDay = nowDate.getDate();
	if(vMon < 10){vMon = "0"+vMon}
	var nowTime = vYear+"-"+vMon+"-"+vDay;
	var beginTime = vYear+"-"+vMon+"-01";

	if($nDate.val() == ""){
		$nDate.val(beginTime);
	}
	if($pDate.val() == ""){
		$pDate.val(nowTime);
	}

})
	//取消订单
	function cancelOrder(t){
		$.ajax({
			url:"__ROOT__/Order/cancelOrder",
			type:"post",
			data:{'orderCode':$(t).attr("ref")},
			success:function(data){
				var data = eval("("+data+")");
				if(data.status == 1){
					layer.msg(data.info);
					window.location.reload();
				}else{
					layer.msg(data.info);
				}
			}
		})
	}
	
	//确认订单
	function doneOrder(t){
		$.ajax({
			url:"__ROOT__/Order/doneOrder",
			type:"post",
			data:{'orderCode':$(t).attr("ref")},
			success:function(data){
				var data = eval("("+data+")");
				if(data.status == 1){
					layer.msg(data.info);
					window.location.reload();
				}else{
					layer.msg(data.info);
				}
			}
		})
	}
	//申请退款
	function applyReturnOrder(t){
		layerDialog("申请退款",'__ROOT__/Order/refund?orderCode='+$(t).attr("ref"),"720px","620px",true);
	}
</script>
</html>
